package com.braveman.im.ui.activity.message;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ExpandableListView;
import android.widget.RelativeLayout;

import com.braveman.im.R;
import com.braveman.im.bean.ChildBean;
import com.braveman.im.bean.GroupBean;
import com.braveman.im.bean.GroupDesBean;
import com.braveman.im.manager.ApiManager;
import com.braveman.im.ui.adapter.AnnouncementAdapter;
import com.braveman.im.utils.UtilsStyle;
import com.ht.baselibs.retrofit.NetCallBack;
import com.ht.baselibs.ui.base.BaseActivity;
import com.ht.baselibs.ui.widget.TitleBarView;
import com.ht.baselibs.utils.ActivityUtils;
import com.vondear.rxtools.RxBarTool;

import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;
import retrofit2.Response;

/**
 * 作者 昊昊.
 * 年份 2017/10/19.
 * 时间 17:38.
 * 项目名称 ZhengQiApp.
 */

/**
 * 群公告
 */
public class AnnouncementActivity extends BaseActivity {

    private ExpandableListView expandableListView;
    private RelativeLayout relativeLayout;
    private AnnouncementAdapter adapter;
    private List<GroupBean> list = new ArrayList<>();
    private String groupId;

    @Override
    protected void initTitleBar() {
        mTitleBarView.setTitleText("群公告").addActions(new TitleBarView.Action("发布") {
            @Override
            public void performAction(View view) {
                Bundle bundle = new Bundle();
                bundle.putString("groupId", groupId);
                bundle.putString("groupType", "individual");
                ActivityUtils.startActivity(AnnouncementActivity.this, SendCompanyNotifyActivity.class, bundle);
            }
        }).setLeftBtnIcon(R.mipmap.back_black).setOnLeftBtnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ActivityUtils.finishActivity(AnnouncementActivity.this);
            }
        });
    }

    @Override
    protected boolean isStaticPage() {
        return true;
    }

    @Override
    protected int initContentView() {
        UtilsStyle.setStatusBarMode(this, true);
        RxBarTool.FlymeSetStatusBarLightMode(getWindow(), true);
        RxBarTool.MIUISetStatusBarLightMode(getWindow(), true);
        return R.layout.activity_announcement;
    }

    @Override
    protected void initIntentData(Intent callIntent) {
        groupId = callIntent.getStringExtra("groupId");
    }

    @Override
    protected void initChildView() {
        expandableListView = (ExpandableListView) findViewById(R.id.activity_Ex_announcement);
        relativeLayout = (RelativeLayout) findViewById(R.id.activity_announcement_rl);
    }


    @Override
    protected void initChildData() {

        ChildBean cb = new ChildBean();
        cb.id = TextUtils.isEmpty(groupId) ? "118323368490569728" : groupId;
        // cb.groupId = "123123123";
        ApiManager.getApi().getChildBean(cb.id, 1, 100).enqueue(new NetCallBack<GroupDesBean>() {
            @Override
            protected void onSuccess(Call<GroupDesBean> call, Response<GroupDesBean> response) {
                GroupDesBean groupDesBean = response.body();
                for (int i = 0; i < groupDesBean.dataList.size(); i++) {
                    List<ChildBean> list1 = new ArrayList<>();
                    ChildBean cb12 = new ChildBean(groupDesBean.dataList.get(i).subject, groupDesBean.dataList.get(i).detail);
                    list1.add(cb12);
                    GroupBean gb1 = new GroupBean(groupDesBean.dataList.get(i).subject, groupDesBean.dataList.get(i).publishTime, list1);
                    list.add(gb1);
                }
                adapter = new AnnouncementAdapter(list, AnnouncementActivity.this);
                expandableListView.setAdapter(adapter);
                expandableListView.setGroupIndicator(null);
                expandableListView.collapseGroup(0);
            }
        });

        //ex控件点击事件
        expandableListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
            @Override
            public boolean onGroupClick(ExpandableListView expandableListView, View view, int i, long l) {
                if (expandableListView.isGroupExpanded(i)) {
                    relativeLayout.setVisibility(View.VISIBLE);
                    expandableListView.collapseGroup(i);
                } else {
                    relativeLayout.setVisibility(View.GONE);
                    expandableListView.isGroupExpanded(i);
                }
                return false;
            }
        });
    }

    @Override
    protected void setChildViewListener() {

    }

    @Override
    public void onClick(View v) {
        super.onClick(v);

        switch (v.getId()) {

        }
    }
}
